<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/


Route::get('/', function(){
	return Redirect::to(URL::to(Config::get('app.locale').'/home'));
});

Route::get('/{lang}/home', array('before' => "language",'uses' => 'HomeController@showHome' ) );
Route::get('/{lang}/rss', array('before' => "language",'uses' => 'HomeController@showRSS' ) );


Route::filter('language', function() {
	
	$languages = array('en','my');
	$locale = Request::segment(1);
	if(in_array($locale, $languages)){
		\App::setLocale($locale);
	}else{
		$locale = null;
	}
	
});

/*
| ---------------------------------------------------------------
|  Admin Route
| --------------------------------------------------------------- 
*/
Route::get('admin/login', function() {
	$title = "Login Sabahkini";
	return View::make( 'admin.user.login')->with('title',$title);;
});

Route::post('admin/login', array('uses' => 'UserController@actionLogin')
	
);
/*Route::filter('userSession', function() {
	if( Session::has('loggedInAs') ) { 
		return "logged in ".Session::get('loggedInAs')->username ;
	}
});*/
Route::post('admin/logout',function() {
	if( Session::has('loggedInAs') ) {
		Session::forget('loggedInAs');
	}
		return View::make('admin/index', array('status' => 'Logout Succesfully'));
});
Route::get('admin/logout',function(){
	if( Session::has('loggedInAs') ) {
		Session::forget('loggedInAs');
	}
	return Redirect::to('/admin/login'); 
});
/*
Route::get('testImages', function() {
	return View::make( 'testImages' );
});


Route::get('users', function()
{
	return View::make('users');
});
Route::get('testConnection/{id}', function($id)
{

	//$user = User::find(1);
	echo $id;

	//return View::make('testConnection');

	//echo $user->url();
});
Route::get('user/{name}', function($name)
{
	echo $name;
})
->where('name', '[A-Za-z]+');
Route::get('user/{id}', function($id)
{
	echo $id;
    
})
->where('id', '[0-9]+');
Route::get('user/{mix}', function($mix)
{
	echo $mix;
})
->where('mix', '[A-Za-z0-9]+'); 




Route::filter('old', function()
{
	/*	return "here";
    if (Route::input('age') < 200)
    {
        return Route::input('age');
    }
});

Route::get('testFilter/{age}', array('before' => "old",'uses' => 'AuthController@loginForm'
))->where('age', '[0-9]+'); */

//Route admin
Route::group(array('before' => 'checkLogin'), function(){	
	Route::get('admin/dashboard', function() {
		$title = "Dashboard Sabahkini";
		return View::make( 'admin.dashboard.index')->with('title',$title);
	});
	
	Route::get('admin/news','NewsController@showNews');
	Route::get('admin/news/add', function() {		
		$title = "News Sabahkini";
		$data = new Category();
		return View::make('admin.news.add')
		->with('listCategory',$data->getListCategory())
		->with('allStatus',Config::get('config.news_status'))
		->with('title',$title);
	});
	Route::post('admin/news/add', 'NewsController@postCreate');
	Route::get('admin/news/edit/{id}','NewsController@getEdit');
	Route::post('admin/news/edit/{id}','NewsController@update');
	Route::get('admin/news/changes/{id}','NewsController@changes');
	
	Route::get('admin/news/delete/{id}','NewsController@delete');
	
	Route::get('admin/category','CategoryController@showIndex');	
	Route::get('admin/category/add', function() {	
		return View::make('admin.category.add')
		->with('allLang',Language::get())
		->with('title',"Add Category Sabahkini")
		->with('allStatus',Config::get('config.category_status'));
	});
	
	Route::get('admin/category/edit/{id}','CategoryController@getEdit');
	Route::post('admin/category/edit/{id}','CategoryController@update');
	Route::post('admin/category/add', 'CategoryController@postCreate');
	Route::get('admin/category/changes/{id}','CategoryController@changes');
	Route::get('admin/category/delete/{id}','CategoryController@destroy');
	Route::get('admin/setting', function() {
		$title = "Setting Sabahkini";
		return View::make( 'admin.setting.index')->with('title',$title);
	});
});
Route::get('/{lang}/c-{id}-{category}.html', array('before' => "language",'uses' => 'HomeController@listCat' ) );
Route::get('/{lang}/news/{id}/{title}/{status}', array('as' => 'newsDetails', 'before' => "language",'uses' => 'NewsController@showNewsDetails' ) );
Route::post('/{lang}/comment/postnew/{newsID}/', array('before' => "language",'uses' => 'CommentController@postComment' ) );
Route::get('/{lang}/contactUs', array('before' => "language",'uses' => 'ContactUsController@showContactUs' ) );
Route::post('/{lang}/contactUs/postnew/', array('before' => "language",'uses' => 'ContactUsController@postFeedback' ) );
Route::post('/getdata','HomeController@lisNewOnCat');
Route::get('/{lang}/search','HomeController@search');
Route::post('/searchdata','HomeController@dataseach');




